import React , { useEffect, useState }from 'react'
import { useLocation } from 'umi'
import { Button } from 'antd'
import { messageTypeEnum } from './enum'
import { getPublicDownloadUrl } from '@/service/personal'



export default function Details ()  {

  const location : any = useLocation()
  const [type, setType] = useState('')
  const [sourceData, setSourceData] = useState<any>({})

  useEffect(()=>{
    setType(location?.query?.type)
    setSourceData(location?.state)
  },[])

  const Type1 = (
 
      <div>
        <p>消息类型：{messageTypeEnum[sourceData?.messageType]}</p>
        <p>消息模块：</p>
        <p>当前状态：</p>
        <p>消息内容：{sourceData?.messageContent}</p>
        <p>推送时间：{sourceData?.messageDate}</p>
      </div>
    )
  

  const Type2 =  (
      <div>
        <p>消息类型：{messageTypeEnum[sourceData?.messageType]}</p>
        <p>消息标题: </p>
        <p>消息内容：{sourceData?.messageContent}</p>
        <p>消息附件: <Button type='link' onClick={async()=>{
          const url =  await getPublicDownloadUrl({ id:[sourceData?.giftKey] })
          console.log(url)
        }}>{sourceData?.giftKey}</Button></p>
        <p>推送时间：{sourceData?.messageDate}</p>
      </div>
    )
  

  // eslint-disable-next-line react/no-unstable-nested-components
  function RenderModul() {
    if(type){
      if(type === '1'){
        return Type1
      }
      if(type === '2'){
        return Type2
      }
    }
    return <></>
  }


  return (
    <div>
      <RenderModul/>
    </div>
  )
}